<template>
  <div class="main">
    <ul class="todo-list">
      <li v-for="item in list" :key="item.id" :class="{'completed': item.done}">
        <div class="view">
          <input class="toggle" type="checkbox" v-model="item.done"/>
          <label>{{ item.name }}</label>
          <button class="destroy" @click="delTodo(item.id)"></button>
        </div>
      </li>
    </ul>
  </div>
</template>

<script setup>
import { ref, reactive, defineProps, defineEmits } from 'vue'
const props = defineProps(['list'])
const emit = defineEmits(['delTodo'])
const delTodo = id => {
  id && emit('delTodo', id)
}
</script>

<style scoped>
.main {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: left;
}
.todo-list {
  margin: 0;
  padding: 0;
  width: 100%;
  list-style: none;
}
.view {
  display: flex;
  align-items: center;
  justify-content: left;
  width: 100%;
  padding-top: 15px;
  padding-bottom: 15px;
  border-bottom: 1px solid #ccc;
}
.toggle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin-right: 30px;
  appearance: none;
  -moz-appearance: none;
  -webkit-appearance: none;
  background-color: #fff;
  border: 1px solid #ccc;
}
.destroy {
  display: none;
  margin-left: auto;
  margin-right: 30px;
  background-color: transparent;
  border: none;
  cursor: pointer;
  font-size: 16px; /* 调整字体大小 */
  padding: 5px; /* 调整内边距 */
  color: black; /* 调整颜色 */
}
.destroy::before {
  content: "×";
  font-size: 30px; /* 调整字体大小 */
  padding: 5px; /* 调整内边距 */
}
.view:hover{
  /* 鼠标浮动才显示删除 */
  /* 添加过渡动画 */
  .destroy {
    display: block;
  }
}
.completed .toggle {
  border: 1px solid #ccc;
}
.completed .toggle::before {
  content: "✔";
  font-size: 30px;
  color: green;
  display: block;
  margin: 0 auto;
  text-align: center;
  line-height: 40px;
}
</style>